package com.redribbon.droidnoise;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class DroidNoise extends Activity {

	StreamServerService streamService = null;

	

	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // set the global wifiman object (only accessible from Activity)
        NoiseConstants.wifiman = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        
        final Button main_broadcast_button = (Button) findViewById(R.id.main_screen_broadcast_button);
         	main_broadcast_button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click

            	startActivity(new Intent(DroidNoise.this, ServerOptions.class));
            }
        });
        final Button main_listen_button = (Button) findViewById(R.id.main_screen_listen_button);
       	main_listen_button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	startActivity(new Intent(DroidNoise.this, IfAllElseFailsStreamer.class));
            }
        });
        
    }



    /**
     * Class for interacting with the main interface of the service.
     */
    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className,
                IBinder service) {
            // This is called when the connection with the service has been
            // established, giving us the service object we can use to
            // interact with the service.  We are communicating with our
            // service through an IDL interface, so get a client-side
            // representation of that from the raw service object.
            streamService = StreamServerService.Stub.asInterface(service);

            // We want to monitor the service for as long as we are
            // connected to it.
            try {
                streamService.registerCallback(mCallback);
            } catch (RemoteException e) {
                // In this case the service has crashed before we could even
                // do anything with it; we can count on soon being
                // disconnected (and then reconnected if it can be restarted)
                // so there is no need to do anything here.
            }
        }

        public void onServiceDisconnected(ComponentName className) {
            // This is called when the connection with the service has been
            // unexpectedly disconnected -- that is, its process crashed.
            streamService = null;
        }
    };

    /**
     * This implementation is used to receive callbacks from the remote
     * service.
     */
    private StreamServerServiceCallback mCallback = new StreamServerServiceCallback.Stub() {
        /**
         * This is called by the remote service regularly to tell us about
         * new values.  Note that IPC calls are dispatched through a thread
         * pool running in each process, so the code executing here will
         * NOT be running in our main thread like most other things -- so,
         * to update the UI, we need to use a Handler to hop over there.
         */
        public void valueChanged(int value) {
            mHandler.sendMessage(mHandler.obtainMessage(BUMP_MSG, value, 0));
        }
    };

    private static final int BUMP_MSG = 1;

    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case BUMP_MSG:
                    
                    break;
                default:
                    super.handleMessage(msg);
            }
        }

    };
    
    


    
}
